﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Configuration;
using DataAccessLayer;

namespace BusinessLayer
{
    public class EmailClass
    {
        public List<MailAddress> To { get; set; }
        public string From { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public bool IsHtml { get; set; }

        public void Send_Email()
        {
            SmtpClient objClient = new SmtpClient();

            objClient.Host = ConfigurationManager.AppSettings["host"].ToString();
            objClient.Port = Convert.ToInt32(ConfigurationManager.AppSettings["port"].ToString());

            System.Net.NetworkCredential objc = 
                new System.Net.NetworkCredential(
                    ConfigurationManager.AppSettings["username"].ToString(),
                    ConfigurationManager.AppSettings["password"].ToString());

            objClient.Credentials = objc;
            objClient.UseDefaultCredentials = false; 

            MailMessage objMail = new MailMessage();

            foreach (MailAddress m in To)
                objMail.To.Add(m);
            
            objMail.From = new MailAddress(From);
            objMail.IsBodyHtml = IsHtml;
            objMail.Body = Body;
            objMail.Subject = Subject;
            objClient.Send(objMail);
            
        }
    }
}
